package com.example.yjh.recyclerviewtest_314yjh.activity;

        import android.support.v7.app.AppCompatActivity;
        import android.os.Bundle;
        import android.support.v7.widget.LinearLayoutManager;
        import android.support.v7.widget.RecyclerView;
        import android.widget.Toast;

        import com.example.yjh.recyclerviewtest_314yjh.adapter.TcaseAdapter;
        import com.example.yjh.recyclerviewtest_314yjh.R;

        import com.example.yjh.recyclerviewtest_314yjh.bean.TcaseBean;
        import com.example.yjh.recyclerviewtest_314yjh.iface.TcaseListener;
        import com.example.yjh.recyclerviewtest_314yjh.model.TcaseModel;

        import java.util.List;


public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private TcaseAdapter tcaseAdapter;
    private List<TcaseBean> list=null;
    TcaseListener tcaseListener =new TcaseListener() {
        @Override
        public void onResponse(List<TcaseBean> beanList) {
            list=beanList;
            tcaseAdapter.setList(list);
            tcaseAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(MainActivity.this,msg, Toast.LENGTH_SHORT).show();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecycleView();
        TcaseModel tcaseModel =new TcaseModel();
        tcaseModel.getResultList("tcase",2,"rv1l2tidbomann2qn86nln6ur2", tcaseListener);

    }

    private void initRecycleView() {
        recyclerView=(RecyclerView)findViewById(R.id.recyclerview);
        layoutManager=new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        // list=getData();
        tcaseAdapter =new TcaseAdapter(this);
        tcaseAdapter.setList(list);
        recyclerView.setAdapter(tcaseAdapter);
    }

 /*   private List<ArticleBean> getData(){
        List<ArticleBean> list=new ArrayList<ArticleBean>();
        ArticleBean articleBean;
        articleBean=new ArticleBean();
        articleBean.setArticleId(1);
        articleBean.setTitle("标题1");
        articleBean.setDescription("内容1");
        articleBean.setTime("2017-4-1");
        articleBean.setImgid(R.drawable.f1);
        list.add(articleBean);
        articleBean=new ArticleBean();
        articleBean.setArticleId(2);
        articleBean.setTitle("标题2");
        articleBean.setDescription("内容2");
        articleBean.setTime("2017-4-2");
        articleBean.setImgid(R.drawable.f2);
        list.add(articleBean);
        articleBean=new ArticleBean();
        articleBean.setArticleId(3);
        articleBean.setTitle("标题3");
        articleBean.setDescription("内容3");
        articleBean.setTime("2017-4-3");
        articleBean.setImgid(R.drawable.f3);
        list.add(articleBean);
        articleBean=new ArticleBean();
        articleBean.setArticleId(4);
        articleBean.setTitle("标题4");
        articleBean.setDescription("内容4");
        articleBean.setTime("2017-4-4");
        articleBean.setImgid(R.drawable.f4);
        list.add(articleBean);
        articleBean=new ArticleBean();
        articleBean.setArticleId(5);
        articleBean.setTitle("标题5");
        articleBean.setDescription("内容5");
        articleBean.setTime("2017-4-5");
        articleBean.setImgid(R.drawable.f5);
        list.add(articleBean);
        articleBean=new ArticleBean();
        articleBean.setArticleId(6);
        articleBean.setTitle("标题6");
        articleBean.setDescription("内容6");
        articleBean.setTime("2017-4-6");
        articleBean.setImgid(R.drawable.f6);
        list.add(articleBean);
        return  list;

    }*/



}
